package forum.logs;

import java.io.File;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.text.DateFormat;
import java.util.Date;

public class LogPrefeitura implements Serializable {

	public static void gravarErro(Exception exception) {
		try {
			File file = new File("log_prefeitura.txt");
			
			if (!file.exists()) {
				file.createNewFile();
			}
			
			RandomAccessFile raf = new RandomAccessFile(file, "rw");
			raf.seek(raf.length());
			
			DateFormat format = DateFormat.getDateTimeInstance();
			String erro = LogForum.getMenssagemErro(exception);
			
			raf.writeBytes(String.format("%s\n", format.format(new Date()).toString()));
			raf.writeBytes(String.format("%s\n", erro));
			
			raf.writeBytes(String.format("\n%s\n\n", "----------------"));
			raf.close();
		} catch (Exception exception2) {
			exception2.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		try {
			Integer.valueOf("");
		} catch (Exception exception) {
			exception.printStackTrace();
			LogPrefeitura.gravarErro(exception);
		}
	}

}
